<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: soundsQueueExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('soundsQueueExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">soundsQueueExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>This program demonstrates the sound output queue ArSoundsQueueShows how to operate the sounds queue and add WAV files to play.</p>
<p>You may specify up to 10 file names on the command line. This example only demonstrates using the sounds queue for WAV file playback. For demonstration of using the sounds queue for speech synthesis, see the examples provided with either the ArSpeechSynth_Cepstral or ArSpeechSynth_Festival libraries.</p>
<p>Usage: soundQueue <em>&lt;wav file names&gt;</em></p>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ariaTypedefs.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ariaUtil.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArSoundsQueue.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArSoundPlayer.h&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacestd.html">std</a>;</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> queueNowEmpty() {</div><div class="line">  printf(<span class="stringliteral">&quot;The sound queue is now empty.\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> queueNowNonempty() {</div><div class="line">  printf(<span class="stringliteral">&quot;The sound queue is now non-empty.\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> no() {</div><div class="line">  <span class="comment">// just a false tautology</span></div><div class="line">  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv) {</div><div class="line">  <a name="a0"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <span class="comment">//ArLog::init(ArLog::StdErr, ArLog::Verbose);</span></div><div class="line"></div><div class="line">  <span class="comment">// Create the sound queue.</span></div><div class="line">  <a name="_a1"></a><a class="code" href="classArSoundsQueue.html">ArSoundsQueue</a> soundQueue;</div><div class="line"></div><div class="line">  <span class="comment">// Set WAV file callbacks </span></div><div class="line">  soundQueue.<a name="a2"></a><a class="code" href="classArSoundsQueue.html#a7a91b153f0bcf9705d9ab18091d32fe0">setPlayWavFileCallback</a>(<a name="a3"></a><a class="code" href="classArSoundPlayer.html#a814d7e32962633f99ae5229c69502647">ArSoundPlayer::getPlayWavFileCallback</a>());</div><div class="line">  soundQueue.<a name="a4"></a><a class="code" href="classArSoundsQueue.html#a18a4ee9aaa952188792551ee9af2c2ae">setInterruptWavFileCallback</a>(<a name="a5"></a><a class="code" href="classArSoundPlayer.html#ace0317817d565d9328500bbe806eefac">ArSoundPlayer::getStopPlayingCallback</a>());</div><div class="line"></div><div class="line">  <span class="comment">// Notifications when the queue goes empty or non-empty.</span></div><div class="line">  soundQueue.<a name="a6"></a><a class="code" href="classArSoundsQueue.html#abbc9d407d6e76c6a58bd1fc52941fb71">addQueueEmptyCallback</a>(<span class="keyword">new</span> <a name="_a7"></a><a class="code" href="classArGlobalFunctor.html">ArGlobalFunctor</a>(&amp;queueNowEmpty));</div><div class="line">  soundQueue.<a name="a8"></a><a class="code" href="classArSoundsQueue.html#a232be5d28fabf0dcbe95d34be0b8f261">addQueueNonemptyCallback</a>(<span class="keyword">new</span> <a class="code" href="classArGlobalFunctor.html">ArGlobalFunctor</a>(&amp;queueNowNonempty));</div><div class="line"></div><div class="line">  <span class="comment">// Run the sound queue in a new thread</span></div><div class="line">  soundQueue.<a name="a9"></a><a class="code" href="classArSoundsQueue.html#ad8f9600dba4c91cfc0418a011bf3f165">runAsync</a>();</div><div class="line"></div><div class="line">  <span class="comment">// Get WAV file names from command line</span></div><div class="line">  <span class="keywordflow">if</span>(argc &lt; 2) </div><div class="line">  {</div><div class="line">    cerr &lt;&lt; <span class="stringliteral">&quot;Usage: &quot;</span> &lt;&lt; argv[0] &lt;&lt; <span class="stringliteral">&quot; &lt;up to ten WAV sound file names...&gt;\n&quot;</span>;</div><div class="line">    <a name="a10"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(-1);</div><div class="line">  }</div><div class="line">  std::vector&lt;const char*&gt; filenames;</div><div class="line">  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 1; i &lt; min(argc, 11); i++) </div><div class="line">  {</div><div class="line">    filenames.push_back(argv[i]);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// This functor can be used to cancel all sound playback until removed</span></div><div class="line">  <a name="_a11"></a><a class="code" href="classArGlobalRetFunctor.html">ArGlobalRetFunctor&lt;bool&gt;</a> dontPlayItem(&amp;no);</div><div class="line">  </div><div class="line">  <span class="keywordflow">while</span>(<a name="a12"></a><a class="code" href="classAria.html#a573c386c42739be20fa97a99ae65f9ee">Aria::getRunning</a>())</div><div class="line">  {</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Queue is &quot;</span> &lt;&lt; </div><div class="line">      string(soundQueue.<a name="a13"></a><a class="code" href="classArSoundsQueue.html#a55feaa97933ebf630f1373de06853684">isPaused</a>()?<span class="stringliteral">&quot;paused&quot;</span>:(soundQueue.<a name="a14"></a><a class="code" href="classArSoundsQueue.html#ae75d363d5ff3da705f0c4f8d8c52dea8">isPlaying</a>()?<span class="stringliteral">&quot;playing&quot;</span>:<span class="stringliteral">&quot;ready&quot;</span>)) </div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;, with &quot;</span> &lt;&lt; soundQueue.<a name="a15"></a><a class="code" href="classArSoundsQueue.html#a1503e852fae705e109a83ad8820f9fee">getCurrentQueueSize</a>() &lt;&lt; <span class="stringliteral">&quot; pending sounds.&quot;</span> &lt;&lt; endl</div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;Enter a command followed by the enter key:\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tp\trequest pause state (cumulative)\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tr\trequest resume state (cumulative)\n&quot;</span> </div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\ti\tinterrupt current sound\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tc\tclear the queue\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tC\tclear priority &lt; 4 from the queue.\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tn\tAdd &quot;</span> &lt;&lt; filenames[0] &lt;&lt; <span class="stringliteral">&quot; to the queue, but with a condition callback to prevent it playing.\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tv\tAdjust volume -50%\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tV\tAdjust volume +50%\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\to\tAdjust volume -100%\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tO\tAdjust volume +100%\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tl\tAdjust volume -200%\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\tL\tAdjust volume +200%\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\t-\tSet volume adjustment to normal level\n&quot;</span></div><div class="line">      ;</div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i = 0; i &lt; filenames.size(); i++)</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;\tadd &quot;</span> &lt;&lt; filenames[i] &lt;&lt; <span class="stringliteral">&quot; to the queue\n&quot;</span>;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;\tq\tquit\n\n&quot;</span>;</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> c = getchar();</div><div class="line">    <span class="keywordflow">if</span>(c == <span class="charliteral">&#39;\n&#39;</span>)</div><div class="line">      <span class="keywordflow">continue</span>;</div><div class="line">    <span class="keywordflow">switch</span>(c)</div><div class="line">    {</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;p&#39;</span>: soundQueue.<a name="a16"></a><a class="code" href="classArSoundsQueue.html#a7d27d8572c1db27e136a85ae15152d51">pause</a>(); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;r&#39;</span>: soundQueue.<a name="a17"></a><a class="code" href="classArSoundsQueue.html#a2299817c9725d01073f92f06c0faf18d">resume</a>(); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;i&#39;</span>: soundQueue.<a name="a18"></a><a class="code" href="classArSoundsQueue.html#a0a24a9edf0dabfe72ff46a61ebced3a2">interrupt</a>(); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;q&#39;</span>: soundQueue.<a name="a19"></a><a class="code" href="classArSoundsQueue.html#a4ae132843ebaa7291a21063c582bdf8f">stop</a>(); <a name="a20"></a><a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(100); <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;c&#39;</span>: soundQueue.<a name="a21"></a><a class="code" href="classArSoundsQueue.html#a2e5eb64d85322adf020091d66cfe2cf1">clearQueue</a>(); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;C&#39;</span>: soundQueue.<a name="a22"></a><a class="code" href="classArSoundsQueue.html#a2e8e700c60788cd59136a4c6af84d57b">removePendingItems</a>(4); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;n&#39;</span>: </div><div class="line">      {</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Adding \&quot;&quot;</span> &lt;&lt; filenames[0] &lt;&lt; <span class="stringliteral">&quot;\&quot; but with a condition callback that will prevent it from playing...\n&quot;</span>;</div><div class="line">        <a name="_a23"></a><a class="code" href="classArSoundsQueue_1_1Item.html">ArSoundsQueue::Item</a> item = soundQueue.<a name="a24"></a><a class="code" href="classArSoundsQueue.html#a8a91d3b696ae76124ca0bd836bcc6136">createDefaultFileItem</a>(filenames[0]);</div><div class="line">        item.<a name="a25"></a>playbackConditionCallbacks.push_back(&amp;dontPlayItem);</div><div class="line">        soundQueue.<a name="a26"></a><a class="code" href="classArSoundsQueue.html#a6c1813ed5c1b57c77b6f4d3f7c938988">addItem</a>(item);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;v&#39;</span>: <a name="a27"></a><a class="code" href="classArSoundPlayer.html#a7af22400dc046250534ca2ba6712621f">ArSoundPlayer::setVolumePercent</a>(-50.0); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;V&#39;</span>: <a class="code" href="classArSoundPlayer.html#a7af22400dc046250534ca2ba6712621f">ArSoundPlayer::setVolumePercent</a>(50.0); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;o&#39;</span>: <a class="code" href="classArSoundPlayer.html#a7af22400dc046250534ca2ba6712621f">ArSoundPlayer::setVolumePercent</a>(-100.0); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;O&#39;</span>: <a class="code" href="classArSoundPlayer.html#a7af22400dc046250534ca2ba6712621f">ArSoundPlayer::setVolumePercent</a>(100.0); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;l&#39;</span>: <a class="code" href="classArSoundPlayer.html#a7af22400dc046250534ca2ba6712621f">ArSoundPlayer::setVolumePercent</a>(-200.0); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;L&#39;</span>: <a class="code" href="classArSoundPlayer.html#a7af22400dc046250534ca2ba6712621f">ArSoundPlayer::setVolumePercent</a>(200.0); <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;-&#39;</span>: <a class="code" href="classArSoundPlayer.html#a7af22400dc046250534ca2ba6712621f">ArSoundPlayer::setVolumePercent</a>(0.0); <span class="keywordflow">break</span>; </div><div class="line">      <span class="keywordflow">default</span>:</div><div class="line">        <span class="keywordflow">if</span>(filenames.size() &gt; 0 &amp;&amp; c &gt;= <span class="charliteral">&#39;0&#39;</span> &amp;&amp; c &lt;= <span class="charliteral">&#39;9&#39;</span>)</div><div class="line">        {</div><div class="line">          <span class="keywordtype">size_t</span> i = c - <span class="charliteral">&#39;0&#39;</span>;</div><div class="line">          <span class="keywordflow">if</span>(i &lt; filenames.size()) </div><div class="line">          {</div><div class="line">            cout &lt;&lt; <span class="stringliteral">&quot;Adding \&quot;&quot;</span> &lt;&lt; filenames[i] &lt;&lt; <span class="stringliteral">&quot;\&quot; to the queue...\n&quot;</span>; </div><div class="line">            soundQueue.<a name="a28"></a><a class="code" href="classArSoundsQueue.html#a77f50ee7d294994b84a834bd307b634f">play</a>(filenames[i]);</div><div class="line">          } </div><div class="line">        }</div><div class="line">    }</div><div class="line">  }</div><div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;ended.\n&quot;</span>;</div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
